<?php
/**
 * Created by PhpStorm.
 * User: mark
 * Date: 18-10-21
 * Time: 下午1:06
 * 事件
 */
namespace Event;

abstract class EventIdFactory{

  public function getId(string $class_name,string $arg_id):string {
    return $class_name.$this->argId($arg_id);
  }

  abstract protected function argId(string $arg_id):string ;
}

class AllEventIdFactory extends EventIdFactory {

  public function argId(string $arg_id):string {
    return "_all";
  }
}

class ArgEventIdFactory extends EventIdFactory {

  public function argId(string $arg_id):string {
    return "_arg_".$arg_id;
  }
}

class Event{
  private $arg_id;
  private $id_factory;

  public function __construct(string $arg_id) {
    $this->arg_id = $arg_id;
    $this->id_factory = new ArgEventIdFactory();
  }

  public function setIdFactory(EventIdFactory $eventIdFactory){
    $this->id_factory = $eventIdFactory;
  }

  public function canAutoRegister():bool {
    return true;
  }

  public function getId():string {
    return get_class($this);
    //return $this->id_factory->getId(get_class($this),$this->arg_id);
  }

  public function getArgId(){
    return $this->arg_id;
  }

  /**
   * @return array ["event" => Event,"handlers" => [....]]
   */
  public function getHandlers():array {
    return [];
  }
}

class LoginEvent extends Event{
  public function __construct(string $user_id) {
    parent::__construct($user_id);
  }
}
